package br.com.medical.shop.web.controladores.servico;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {
	
	@Autowired
	private OpenMeetingsService openMeetingsService;
	
	public String getIdSessionAdmin(){
		String username = "admin";
		String userpass = "admin";
		
		String session = getIdSession();
		openMeetingsService.getValue("http://localhost:5080/openmeetings/services/UserService/loginUser?SID="+session+"&username="+username+"&userpass="+userpass, null);
		return session;
	}
	
	private String getIdSession(){
		return openMeetingsService.getValue("http://localhost:5080/openmeetings/services/UserService/getSession","session_id");
	}
	
	public String getHash(HttpServletRequest request) {
		// TODO Auto-generated method stub
		String session = getIdSessionAdmin();
		String name = request.getSession().getAttribute("name").toString();
		String lastName = request.getSession().getAttribute("lastName").toString();
		String id_room = request.getParameter("room_id");
		int moderacao = request.getSession().getAttribute("name").toString().equals("admin") ? 1: 0;
		
		return openMeetingsService.getValue("http://localhost:5080/openmeetings/services/UserService/setUserObjectAndGenerateRoomHash?"
				+ "SID="+session
				+ "&externalUserId=6"
				+ "&firstname="+name
				+ "&lastname="+lastName
				+ "&profilePictureUrl=http://superinfo.no-ip.org/eproinfo/sistema/exibir_imagem.htm?propimg=true&codimgCodUsuario=46&largimg=160&altimg=200&ctximg=Feminino"
				+ "&externalUserType=3"
				+ "&room_id="+id_room
				+ "&becomeModeratorAsInt="+moderacao
				+ "&showAudioVideoTestAsInt=1",null);
	}
	
	public String error( String session, String erroId){
		return openMeetingsService.getValue("http://localhost:5080/openmeetings/services/UserService/getErrorByCode?SID="+session+"&errorid="+erroId+"&language_id=6", "errmessage");
	}
}
